import { _decorator, Button, Component, Node, tween, UIOpacity } from 'cc';
import { UIBase } from './UIBase';
import { UISkill } from './UISkill';
import { AudioManager } from '../game/AudioManager';
import { BeginItem } from './item/BeginItem';
import { Orientation, UIManager } from './UIManager';
import { EventListener } from '../game/EventListener';
import { Events } from '../game/Events';
const { ccclass, property } = _decorator;

@ccclass('UIBegin')
export class UIBegin extends UIBase {
    @property({ type: BeginItem, displayName: "竖版" })
    portraitPanel: BeginItem = null;
    @property({ type: BeginItem, displayName: "横版" })
    landscapePanel: BeginItem = null;

    start() {
        this.landscapePanel.onBegin = this.onBtnStartClick.bind(this);
        this.portraitPanel.onBegin = this.onBtnStartClick.bind(this);
        this.initOrientationUI();
        EventListener.on(Events.OrientationChange, this.initOrientationUI, this);
    }

    onBtnStartClick() {
        AudioManager.Instance.playUIClick();
        this.onHide();
        UISkill.instance.onShow();
    }

    private initOrientationUI() {
        const isportrait = UIManager.Instance.orientation === Orientation.Portrait;
        this.landscapePanel.node.active = !isportrait;
        this.portraitPanel.node.active = isportrait;
    }
}